﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

public partial class RoomStatus : System.Web.UI.Page
{
    private SqlDataReader sdr = null;
    DataTable dt = new DataTable();
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void Display_Click(object sender, EventArgs e)
    {
        try
        {
            sqlhelper.conn.Open();
            string sql = "select HM_RoomStatus.HM_RCategoryId,HM_RoomCategory.HM_RArea,HM_RoomCategory.HM_RBedNum,HM_RoomCategory.HM_RPrice,HM_RoomCategory.HM_RAirCondition,HM_RoomCategory.HM_RTV,HM_RoomStatus.HM_RStatus from HM_RoomCategory, HM_RoomStatus where HM_RoomCategory.HM_RCategoryId = HM_RoomStatus.HM_RCategoryId and HM_RoomCategory.HM_RName = '" + DropDownList1.SelectedValue + "'";
            SqlDataAdapter sda = new SqlDataAdapter(sql, sqlhelper.conn);
            DataSet ds = new DataSet();
            sda.Fill(ds);
            GridView1.DataSource = ds;
            GridView1.DataBind();
            ds.Clear();
        }
        catch
        {
            Response.Write("<script>alert('查找错误，请查看相关代码！')</script>");
        }
        finally
        {
            sqlhelper.conn.Close();
        }
    }

    protected void Update_Click(object sender, EventArgs e)
    {
        try
        {
            sqlhelper.conn.Open();
            string sql1 = string.Format("update HM_RoomStatus set HM_RStatus={0} where HM_RCategoryId={1}", TextBox2.Text.Trim(), TextBox1.Text.Trim());
            SqlCommand cmd = new SqlCommand(sql1, sqlhelper.conn);
            cmd.ExecuteNonQuery();
            if (TextBox2.Text.Trim()=="1")
            {
                string sql2 = "delete from oroominfor where oroominfor.roomno='" + TextBox1.Text.Trim() + "'";
                SqlCommand cmd1 = new SqlCommand(sql2, sqlhelper.conn);
                cmd1.ExecuteNonQuery();
            }
            Response.Write("<script>alert('修改成功，请查看相关代码！')</script>");
            string sql = "select HM_RoomStatus.HM_RCategoryId,HM_RoomCategory.HM_RArea,HM_RoomCategory.HM_RBedNum,HM_RoomCategory.HM_RPrice,HM_RoomCategory.HM_RAirCondition,HM_RoomCategory.HM_RTV,HM_RoomStatus.HM_RStatus from HM_RoomCategory, HM_RoomStatus where HM_RoomCategory.HM_RCategoryId = HM_RoomStatus.HM_RCategoryId and HM_RoomCategory.HM_RCategoryId = '" + TextBox1.Text.Trim() + "'";
            SqlDataAdapter sda = new SqlDataAdapter(sql, sqlhelper.conn);
            DataSet ds = new DataSet();
            sda.Fill(ds);
            GridView1.DataSource = ds;
            GridView1.DataBind();
            ds.Clear();
        }
        catch
        {
            Response.Write("<script>alert('修改失败，请查看相关代码！')</script>");
        }
        finally
        {
            sqlhelper.conn.Close();
        }
    }
}